<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      width: 100px;
      height: 100px;
      position: absolute;
      background-color: skyblue;
    }
  </style>
</head>

<body>
  <div class="box"></div>
  <script>
    const box = document.querySelector('.box')

    // const id = setInterval(() => {
    //   if (box.offsetLeft >= 200) {
    //     box.style.left = '200px'
    //     window.clearInterval(id)
    //     return
    //   }
    //   box.style.left = `${box.offsetLeft + 1}px`
    // }, 1000 / 60)

    function run () {
      if (box.offsetLeft >= 200) {
        box.style.left = '200px'
        return
      }
      box.style.left = `${box.offsetLeft + 1}px`
      window.requestAnimationFrame(run)
    }

    window.requestAnimationFrame(run)
  </script>
</body>

</html>
